#pragma once

#include <QObject>
#include <QObject>
#include <QVariant>
#include <QTimer>
#include <QSharedPointer>
#include <QNetworkAccessManager>
#include <QMutexLocker>
#include <QVector>
#include <QtConcurrent/QtConcurrent>

struct ResponseContent
{
	int StatusCode;  //-1  500 200
	QString BodyContent;
	QString ErrorMessage;
	int RTT;
};

class QNetworkHttpClientPrivate;
class QNetworkHttpClient  : public QObject
{
	Q_OBJECT
public:
	QNetworkHttpClient(const QString& server, int port = 80,QObject *parent = nullptr);
	~QNetworkHttpClient();


public: //  /api/
	QSharedPointer<ResponseContent> getJsonSync(const QString& subPath,int timeout = 3000, int tryTimes = 1);
	QSharedPointer<ResponseContent> postJsonSync(const QString& subPath,const QString& sendJsonContent, int timeout = 3000, int tryTimes = 1);

	QFuture<QSharedPointer<ResponseContent>> getJsonASync(const QString& subPath, int timeout = 3000, int tryTimes = 1);
	QFuture<QSharedPointer<ResponseContent>> postJsonASync(const QString& subPath, const QString& sendJsonContent, int timeout = 3000, int tryTimes = 1);

	//ui 线程执行 不阻塞 UI其它消息
	QSharedPointer<ResponseContent> getJsonASyncNonblocking(const QString& subPath, int timeout = 3000, int tryTimes = 1);
	QSharedPointer<ResponseContent> postJsonASyncNonblocking(const QString& subPath, const QString& sendJsonContent, int timeout = 3000, int tryTimes = 1);

	QSharedPointer<ResponseContent> postFileFromSync(const QString& subPath, const QVector<QString>& fileList, int timeout = 30000, int tryTimes = 1);

private:
	QNetworkHttpClientPrivate* d;
};
